package com.susallwave.srcb.controller.sys.rbac;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.susallwave.srcb.entity.sys.UserRole;
import com.susallwave.srcb.response.Result;
import com.susallwave.srcb.service.sys.UserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户角色关系表 前端控制器
 * </p>
 *
 * @author MyBatisPlusGenerator
 * @since 2025-07-20
 */
@RestController
@RequestMapping("/user-role")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "用户角色管理")
public class UserRoleController {

    private final UserRoleService userRoleService;

    @ApiOperation(value = "获取用户角色", notes = "使用userAcct获取用户角色")
    @GetMapping("/userRoles")
    public Result<List<UserRole>> userRoles(@RequestParam String userAcct) {
        return Result.success(userRoleService.userRoles(userAcct));
    }

    @ApiOperation(value = "角色列表", notes = "角色列表")
    @GetMapping("/list")
    public Result<IPage<UserRole>> listRoles(@RequestParam(defaultValue = "1") int pageNum,
                                             @RequestParam(defaultValue = "10") int pageSize,
                                             @RequestParam String userAcct,
                                             @RequestParam String roleCode) {
        return userRoleService.listRoles(pageNum,pageSize,userAcct,roleCode);
    }

    @ApiOperation(value = "为用户设置角色", notes = "为用户设置角色")
    @PostMapping("/set")
    public Result<Void> setUserRoles(@RequestParam String userAcct, @RequestBody List<String> roleCodes) {
        return userRoleService.setUserRoles(userAcct, roleCodes);
    }
}
